﻿namespace Creek.Serialize
{
    using System.IO;

    public static class Extensions
    {
        #region Public Methods and Operators

        public static T FromBytes<T>(this T target, byte[] buffer)
        {
            var f = new Serializer(true);
            var mem = new MemoryStream(buffer);
            return (T)f.Deserialize(mem);
        }

        public static byte[] ToBytes(this object o)
        {
            var f = new Serializer(true);
            var mem = new MemoryStream();
            f.Serialize(o, mem);
            return mem.ToArray();
        }

        #endregion
    }
}